<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div id="app" class="container">
    <h1>The Activity Page</h1>
    <button type="button" class="btn btn-primary btn-sm"
            data-toggle="modal" data-target="#myModal">创建活动
    </button>
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"
                            aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                    <h4 class="modal-title" id="myModalLabel">创建活动</h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal"  method="post" id="saveFormId">
                        <div class="form-group">
                            <label for="titleId" class="col-sm-2 control-label">标题</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="title" id="titleId" placeholder="title">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="categoryId" class="col-sm-2 control-label">类型</label>
                            <div class="col-sm-10">
                                <select id="categoryId" name="category" class="form-control">
                                    <option value="教育培训">教育培训</option>
                                    <option value="企业活动">企业活动</option>
                                    <option value="交友活动">交友活动</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="startTimeId" class="col-sm-2 control-label">开始时间</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control form_datetime"
                                       name="startTime" id="startTimeId" placeholder="start time">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="endTimeId" class="col-sm-2 control-label">结束时间</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control form_datetime"
                                       name="endTime" id="endTimeId" placeholder="end time">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="remarkId" class="col-sm-2 control-label">备注</label>
                            <div class="col-sm-10">
                                <textarea type="text" class="form-control" rows="5" name="remark" id="remarkId">
                                </textarea>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary" onclick="doSaveObject()">
                        Save Changes
                    </button>
                </div>
            </div>
        </div>
    </div>
    <table class="table">
        <thead>
        <tr>
            <th>title</th>
            <th>Category</th>
            <th>StartTime</th>
            <th>EndTime</th>
            <th>State</th>
            <th>Operation</th>
        </tr>
        </thead>
        <tbody>
        <tr v-for="a in activitys">
            <td>{{a.title}}</td>
            <td>{{a.category}}</td>
            <td>{{a.startTime}}</td>
            <td>{{a.endTime}}</td>
            <td>{{a.state?'有效':'无效'}}</td>
            <td>
                <button type='button'>delete</button>
            </td>
        </tr>
        </tbody>
    </table>
</div>
<script src="js/axios.min.js"></script>
<script src="js/vue.js"></script>
<script src="js/jquery.min.js"></script>
<script src="bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<script>

    function doSaveObject() {
        //1.定义url
        let url = "/activity/doSaveActivity";
        //2.定义请求参数
        var params =
            $("#saveFormId").serialize();//serialize()为jquery中直接获取表单数据方法
        console.log("params", params);
        //3.发送异步请求
        var that = this;
        $.ajax({
            type: "post",
            url: url,
            data: params,
            success: function (result) {
                console.log(this);
                alert(result);
                //隐藏模态框
                $('#myModal').modal('hide');
                //重新执行查询，局部刷新
                that.vue.doFindActivitys();
            }
        });
    }

    var vue = new Vue({
        el: "#app",
        data: {
            activitys: {}
        },
        methods: {
            doFindActivitys() {
                let url = `/activity/doFindActivitys`;
                axios.get(url)
                    .then((rs) => {
                        console.log(rs.data);
                        this.activitys = rs.data;
                    })
            }
        },
        mounted() {
            this.doFindActivitys();
        }
    });
</script>
</body>
</html>